﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Perceiveit.Xml.Converters
{

    #region public class IntXConverter : XConverter<int>

    public class IntXConverter : XConverter<int>
    {
        public override int FromString(string value)
        {
            int i;
            if (string.IsNullOrEmpty(value) || !int.TryParse(value, out i))
                i = 0;
            return i;
        }

        public override string ToString(int value)
        {
            return value.ToString();
        }
    }

    #endregion


    public class IntFormattedXConverter : FormattableXConverter<int>
    {

        public IntFormattedXConverter(string format, IFormatProvider formatter)
            : base(format, formatter)
        {
        }

        public override int FromString(string value)
        {
            int i;
            if (string.IsNullOrEmpty(value) || !int.TryParse(value, System.Globalization.NumberStyles.Any, this.Formatter, out i))
                i = 0;
            return i;
        }

        public override string ToString(int value)
        {
            return value.ToString(this.Format, this.Formatter);
        }
    }
}
